package br.com.virtual.base.uteis;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import br.com.virtual.cadastrar.model.Endereco;

public class EnderecoDataModel extends ListDataModel<Endereco> implements
		SelectableDataModel<Endereco> {

	public EnderecoDataModel() {
		super();
	}

	public EnderecoDataModel(List<Endereco> list) {
		super(list);
	}

	@Override
	public Endereco getRowData(String arg0) {

		@SuppressWarnings("unchecked")
		List<Endereco> enderecos = (List<Endereco>) getWrappedData();

		for (Endereco end : enderecos) {
			if (end.getId().toString().equals(arg0))
				return end;
		}

		return null;
	}

	@Override
	public Object getRowKey(Endereco endereco) {
		return endereco.getId();
	}

}
